//
//  ViewController.m
//  摇动碎屏
//
//  Created by student on 16/4/5.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
//#import <CoreMotion/CoreMotion.h>// 运动的框架
#import <AudioUnit/AudioUnit.h>//短声音的框架
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()
{
    SystemSoundID soundID;
}
//@property (nonatomic,strong) CMMotionManager *motionManager;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 创建运动管理器
//    self.motionManager = [[CMMotionManager alloc] init];
    self.imageView.image = [UIImage imageNamed:@"home"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 检测运动(不需要知道xyz具体加速度数值) 比如做摇一摇的功能
- (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
    if(soundID == 0)
    {
        NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"glass" withExtension:@"wav"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(soundURL), &soundID);
    }
    //播放
    AudioServicesPlaySystemSound(soundID);
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
    self.imageView.image = [UIImage imageNamed:@"homebroken"];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s",__func__);
    self.imageView.image = [UIImage imageNamed:@"home"];
}


@end
